<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__task}">
      <wms-form v-model="dataForm" :formList="formList" :table-column="tableColumn" :advanced="advanced"
        @check-change="checkChange" @changeAdvance="changeAdvance" @getDataList="getDataList" @getReset="getReset">
        <el-form-item>
          <!-- <el-button v-if="$hasPermission('wms:task:delete')" type="warning" @click="retaskHandle()">{{ "任务取消"
          }}</el-button> -->
        </el-form-item>
      </wms-form>
      <wms-table ref="wmsTable" class="wmsTaskTable" v-model="dataForm" :page="page" :total="total" :limit="limit" :tableData="dataList"
        :table-column="column" :module-options="mixinViewModuleOptions" :dataListLoading="dataListLoading"
        :showSelection="true" @addOrUpdateHandle="addOrUpdateHandle"
        @dataListSelectionChangeHandle="dataListSelectionChangeHandle" @deleteHandle="deleteHandle"
        @pageSizeChangeHandle="pageSizeChangeHandle" @pageCurrentChangeHandle="pageCurrentChangeHandle" />
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from "./components/task-add-or-update";
import { formList, tableColumn } from './config'
import wmsTable from '@/components/wms-table'
import wmsForm from '@/components/wms-form'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      addOrUpdateVisible: false,
      mixinViewModuleOptions: {
        getDataListURL: '/wms/task/page',
        getDataListIsPage: true,
        exportURL: '/wms/task/export',
        deleteURL: '/wms/task',
        deleteIsBatch: true,
        deleteIsBatchKey: 'taskId'
      },
      dataForm: {
        taskId: ''
      },
      formList,
      tableColumn,
      column: [],
      advanced: false
    }
  },
  components: {
    wmsTable,
    wmsForm,
    AddOrUpdate
  },
  methods: {
    retaskHandle(id) {
      if (!id && this.dataListSelections.map(item => item.taskId) <= 0) {
        return this.$message({
          message: this.$t('prompt.retask'),
          type: 'warning',
          duration: 1000
        })
      }
      this.$confirm(this.$t('prompt.info', { 'handle': this.$t('retask') }), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.delete(
          `${this.mixinViewModuleOptions.deleteURL}`,
          {
            'data': id ? [id] : this.dataListSelections.map(item => item[taskId])
          }
        ).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.query()
            }
          })
        }).catch(() => { })
      }).catch(() => { })
    }
  }
}
</script>
